<template>
<div class="header">
  <div class="left">
    <img src="~@/assets/images/back2x.png" @click="quit">
  </div>
  <div class="center">
    <div class="title" v-text="title"></div>
    <div class="date" v-if="showDate" v-text="tradedate"></div>
  </div>
  <div class="right">
    <img src="~@/assets/images/share2x.png" @click="share">
  </div>
</div>
</template>
<script>
  import RemoteDAO from '../common/remoteDAO'
  import Cache from '@/common/cache'
  import Jquery from 'jquery'

	export default{
    props:{
      title:{
        type:String
      },
      path:{
        type:String
      },
      time:{
        type:[Number,String]
      },
      status:{
        type:String
      },
      page:{
        type:Number
      }
    },
    data(){
      return {
        tradedate:'',
        showDate:false
      }
    },
    created(){
      this.initEvent();
    },
    mounted(){
      window.addEventListener('scroll',this.scrollFunction)
    },
    beforeDestroy(){
      window.removeEventListener('scroll',this.scrollFunction)
    },
    watch:{
      time:function(){
        this.initEvent();
      }
    },
		methods:{
      initEvent(){
        let self=this;
        let obj={"pagenum": '',"recent": ''};
        RemoteDAO.callZL13100031(obj,self.ZL13100031);
      },
      ZL13100031(result){
        if(result.error=='1'){
          this.tradedate='点击右上角刷新';
        }
        else{
          let data=result.data;
          let bigdata=JSON.parse(data).body[0].bigdata;
          let specData=JSON.parse(bigdata).hits.hits;

          if(specData.length==0){
            this.tradedate='暂无数据';
          }
          else{
            let nameArr=['curmonth','quarter','halfyear','year','2016']
            let selectedDate=''
            if(typeof this.time=='number'){
              if(this.time!=4){
                let selectedArr=specData.filter(value=>{
                  return value._source.recent==nameArr[this.time]
                })
                selectedDate=selectedArr[0]._source.begin_date+'~'+selectedArr[0]._source.end_date
              }
              else{
                selectedDate='20160101~20161231'
              }
              this.tradedate=selectedDate
              this.$store.dispatch('setDateOptions',selectedDate)
            }
            else{
              this.tradedate=this.time.slice(0,4)+'年'+this.time.slice(4,6)+'月'
            }
          }
        }
      },
			refresh(){
				TDAPP.onEvent('002023','');
				TDAPP.send();
        Cache.clear();

				this.$router.replace('/Loading');
				this.$nextTick(function(){
					this.$router.replace(this.path);
				});


			},
			share(){
				TDAPP.onEvent('002001','');
				TDAPP.send();
				this.$router.push({
					path:'/SharePush',
					query:{
            path:this.path,
						time:this.time
					}
				});
			},
      quit(){
        if(this.status){
          this.$store.dispatch('setScrollTop', 1);
          this.$router.replace('/pages/Asset')
        }else{
        window.location.href='gtjanormal://goback';
        }
      },
      scrollFunction(){
        if($(document).scrollTop() != 0){
          this.showDate=true
        }
        else{
          this.showDate=false
        }
      }
		}
	}
</script>
<style scoped>
.header {
overflow: hidden;
  width: 100%;
  height: 88px;
  background-image: url(~@/assets/images/headerBgImage.png);
  background-size: 100%;
  overflow: hidden;
  display: flex;
  color: #fff;
  position: fixed;
  top: 0;
  z-index: 9;
  margin-top: 0;
}

.header>div {
  width: 1px;
  height: 100%;
  flex-grow: 1;
}

.left {
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
}

.left img {
  height: 36px;
  margin-left: 20px;
}

.center {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
}

.title {
  font-size: 36px;
  width: 100%;
}

.date {
  font-size: 20px;
  width: 100%;
}

.right {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
}

.right img {
  height: 36px;
  margin-right: 30px;
}
</style>
